package com.wqb.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wqb.server.pojo.Employee;
import com.wqb.server.pojo.RespBean;
import com.wqb.server.pojo.RespPageBean;
import com.wqb.server.pojo.Salary;
import com.wqb.server.service.IEmployeeService;
import com.wqb.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 万秋泊
 * @Date: 2022/3/25 19:22
 * @Description: 员工账套
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation(value = "获取所有工资账套")
    @GetMapping("/getAllSalary")
    public List<Salary> getAllSalary() {
        return salaryService.list();
    }

    @ApiOperation(value = "获取所有员工账套")
    @GetMapping("/getEmployeeSalary")
    public RespPageBean getEmployeeSalary(@RequestParam(defaultValue = "1") Integer currentPage,
                                          @RequestParam(defaultValue = "10") Integer size) {
        return employeeService.getEmployeeWithSalary(currentPage, size);
    }


    /**
     * 更新员工账套
     *
     * @param eid 员工id
     * @param sid 账套id
     * @return
     */
    @ApiOperation(value = "更新员工账套")
    @PutMapping("/updateEmployeeSalary")
    public RespBean updateEmployeeSalary(Integer eid, Integer sid) {
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId", sid).eq("id", eid))) {
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}

